package cn.edu.scau.dropship.controller;


import cn.edu.scau.dropship.entity.Save_goods;
import cn.edu.scau.dropship.entity.Save_goodsKey;
import cn.edu.scau.dropship.service.SaveGoodsService;
import cn.edu.scau.dropship.service.StorehouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/savegoods")
public class Save_goodsController {

    @Autowired
    private SaveGoodsService save_goodsService;

    @Autowired
    private StorehouseService storehouseService;

    @PostMapping("/selectSaveGoodsByPrimaryKey")
    @ResponseBody
    public Save_goods selectByPrimaryKey(Integer goodsID , Integer mvoID){
        Save_goodsKey key = new Save_goodsKey(goodsID , mvoID);
        return save_goodsService.selectByPrimaryKey(key);
    }

    @PostMapping("/updateSaveGoodsByPrimaryKey")
    @ResponseBody
    public String  updateByPrimaryKey(Integer goodsID , Integer storehouseID , int goodsNum){
        Save_goods record = new Save_goods(goodsID , storehouseID , goodsNum);
        int re = save_goodsService.updateByPrimaryKey(record);
        if(re == 1) return "更新库存成功";
        return  "更新库存失败";
    }

    @PostMapping("/insertSaveGoods")
    @ResponseBody
    public String insertSaveGoods(Integer goodsID , Integer storehouseID , int goodsNum){
        Save_goods record = new Save_goods(goodsID , storehouseID , goodsNum);
        int re = save_goodsService.insert(record);
        if(re == 1) return "插入成功";
        return "插入有误";
    }



}
